package cn.doitedu.rtdw.udfs;

import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.flink.table.functions.ScalarFunction;

import java.sql.Timestamp;

public class TimeStampTruncateUdf extends ScalarFunction {

    //  2023-03-09 11:04:00.000
    public String eval(Timestamp ts, Integer truncateInterval ){

        long time = ts.getTime();
        long interval = truncateInterval*60*1000L;
        time = time - (time % interval);
        // time = (time/interval)*interval;

        return DateFormatUtils.format(time,"yyyy-MM-dd HH:mm:ss.SSS");
    }


}
